package com.mf.controller;

import com.mf.entity.bo.DeptBo;
import com.mf.entity.dto.dept.DeptDto;
import com.mf.entity.request.dept.DeptRequest;
import com.mf.entity.vo.dept.DeptAndPositionVo;
import com.mf.entity.vo.dept.DeptVo;
import com.mf.service.IDeptService;
import io.github.heollhai.common.config.exceptions.GraceException;
import io.github.heollhai.common.entity.request.publicRequest.UpdateStatusRequest;
import io.github.heollhai.common.enums.EnableOrDisableEnum;
import io.github.heollhai.common.result.Result;
import io.github.heollhai.common.utils.enums.EnumUtils;
import io.github.heollhai.common.utils.tree.TreeUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 部门表
 *
 * @author mf
 * @since 2024-09-20
 */
@RestController
@RequestMapping("personnel/dept/v1")
@Tag(name="部门")
public class DeptController {
    @Resource
    private IDeptService deptService;

    @Operation(summary = "新增|编辑")
    @PostMapping("save")
    public Result<Integer> save(@Valid @RequestBody() DeptDto dept) {
        return Result.success(deptService.insert(dept));
    }

    @Operation(summary = "删除")
    @GetMapping("delete/{id}")
    public Result<Integer> delete(@PathVariable("id") Integer id) {
        return Result.success(deptService.deleteById(id));
    }


    @Operation(summary = "修改状态")
    @PostMapping("changeStatus")
    // 禁用后怎么处理下面的部门以及岗位没有确定下来，这个不是重点后面再进行完成
    public Result<Integer> changeStatus(@RequestBody() UpdateStatusRequest<Integer> updateStatusRequest) {
        return Result.success(deptService.changeStatus(updateStatusRequest));
    }

    @Operation(summary = "获取树结构部门")
    @PostMapping("listByTree")
    public Result<List<DeptVo>> list(@RequestBody() DeptRequest deptRequest) {
        return Result.success(TreeUtils.getRoot(deptService.findByList(deptRequest)));
    }

    @Operation(summary = "获取平铺树结构")
    @PostMapping("ListByFlattenTree")
    public Result<List<DeptVo>> flattenTree(@RequestBody() DeptRequest deptRequest) {
        return Result.success(TreeUtils.flattenTree(deptService.findByList(deptRequest)));
    }

    @Operation(summary = "获取部门以及部门下岗位")
    @GetMapping("listFindByDeptAndPosition")
    public Result<List<DeptAndPositionVo>> listFindByDeptAndPosition() {
        return Result.success(deptService.listFindByDeptAndPosition());
    }


}
